package com.pda.gongpin.presenter;

import com.google.gson.Gson;

import com.pda.gongpin.bean.StorageBinIdBean;
import com.pda.gongpin.bean.WareAreaBean;
import com.pda.gongpin.bean.request.ManualHandRequest;
import com.pda.gongpin.bean.request.StorageBinQueryRequest;
import com.pda.gongpin.bean.request.WareAreaQueryRequest;
import com.pda.gongpin.contract.ManualHandlingContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class ManualHandlingPresenter extends BasePresenter<ManualHandlingContract.View> implements  ManualHandlingContract.Presenter {
    @Override
    public void handiworkOutbound(ManualHandRequest request) {
        NetUtils.geApi().manualHandling(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<StorageBinIdBean>>() {
                    @Override
                    public void accept(BaseAppEntity<StorageBinIdBean> loginBeanBaseAppEntity) throws Exception {
                        getView().showMessage(loginBeanBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getSelectAreaAndStorage() {
        NetUtils.geApi().wareAreaQuery(new WareAreaQueryRequest())
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<WareAreaBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<WareAreaBean>> listBaseAppEntity) throws Exception {
                        getView().setAreaList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void storageBinQuery(StorageBinQueryRequest body, boolean isTo) {
        NetUtils.geApi().storageBinQuery(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<StorageBinIdBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<StorageBinIdBean>> listBaseAppEntity) throws Exception {
                        getView().setStorageBinList(listBaseAppEntity.getData(),isTo);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

}
